package com.lczyfz.wisdom.common.utils;

import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;

public class CodeUtils {
    /**
     * 验证密码是否正确
     * @param inputPassword 用户输入的密码
     * @param codePassword 加密过后的密码
     * */
    public static boolean verifyPassword(String inputPassword,String codePassword){

        String hashAlgorithmName = "SHA-1";
        char[] passwordChar = inputPassword.toCharArray();
        byte[] salt1 = Encodes.decodeHex(codePassword.substring(0,16));

        ByteSource salt = ByteSource.Util.bytes(salt1);                                     //盐
        int hashIterations = 1024;                                                          //加密次数
        Object result = new SimpleHash(hashAlgorithmName, passwordChar, salt, hashIterations);
        String result2=codePassword.substring(0,16)+result.toString();
        return result2.equals(codePassword);

    }
}
